<%@page import="hibari.client.model.Week"%>
<%@page import="com.google.appengine.api.datastore.Query.FilterOperator"%>
<%@page import="hibari.client.model.Music"%>
<%@page import="javax.jdo.PersistenceManager"%>
<%@page import="com.google.appengine.api.datastore.Entity"%>
<%@page import="java.util.Iterator"%>
<%@page import="com.google.appengine.api.datastore.PreparedQuery"%>
<%@page
	import="com.google.appengine.api.datastore.DatastoreServiceFactory"%>
<%@page import="com.google.appengine.api.datastore.DatastoreService"%>
<%@page import="com.google.appengine.api.datastore.Query"%>
<%@page import="hibari.PMF"%>
<%@page import="hibari.server.lib.AdminLog"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
    String role = (String) session.getAttribute("role");
    if (role == null) {
        response.sendRedirect("login.jsp");
    }

    PersistenceManager pm = PMF.get().getPersistenceManager();

    Query query = new Query("Week");
    query.addFilter("alive", FilterOperator.EQUAL, false);
    query.addSort("weekNumber");
    DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
    PreparedQuery pq = ds.prepare(query);
    Iterator<Entity> iter = pq.asIterator();
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Hibari Dashboard</title>
<script type="text/javascript" src="jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="common.js"></script>
<link rel="stylesheet" type="text/css" href="styles.css" />
</head>
<body onload="main()">
	<%=AdminLog.get(session).render(session)%>
	<a href="/Admin/index.jsp">return to console</a>
	<fieldset>
		<legend>Trash Bin</legend>
		<table>
		<tr>
			<th>ID</th>
			<th>week no.</th>
			<th>Title</th>
			<th>Tool</th>
		</tr>

		<%
		    while (iter.hasNext()) {
		        Entity entity = iter.next();
		        Week week = pm.getObjectById(Week.class, entity.getKey());
		%>
		<tr>
			<td><%=week.getKey()%></td>
			<td><%=week.getWeekNumber()%></td>
			<td><%=week.getDate()%></td>
			<td>
				<form action="/edit" enctype="multipart/form-data" method="post">
					<input type="hidden" name="callback"
						value="/Admin/RemovedWeekList.jsp" /> <input type="hidden"
						name="operation" value="restoreWeek"> <input type="hidden"
						name="id" value="<%=week.getKey()%>" /> <input type="submit"
						value="Restore" />
				</form>
			</td>
		</tr>

		<%
		    }
		%>
	</table>
	</fieldset>
</body>
</html>